package com.px.chapter_Nov_1;

import java.util.Random;

/**
 * 处理数组
 */
public class ArraryMath {
    private ArraryMath() {
    }

    /**
     * 厉遍数组
     * @param a
     */
    public static void outArrary(int[] a) {
        for (int d = 0; d < a.length; d++) {
            System.out.print(a[d] + " ");
        }
    }

    /**
     * 填入范围为0到c之类的任意数
     */
    public static void inArraryRandom(int[] a, int c) {
        Random random = new Random();

        for (int q = 0; q < a.length; q++) {
            a[q] = random.nextInt(c);
        }
    }

    /**
     * 对两个数组合并
     */
    public static int[] arraryLink(int a[], int b[]) {
        int c[] = new int[a.length + b.length];
        for (int d = 0; d < a.length; d++) {
            c[d] = a[d];

        }
        for (int d = a.length, i = 0; d < a.length + b.length; d++, i++) {
            c[d] = b[i];
        }
        return c;
    }

    /**
     * 厉遍二维数组
     */
    public static void outArrary(int[][] dd) {
        for (int a = 0; a < dd.length; a++) {
            for (int b = 0; b < dd[a].length; b++) {
                System.out.print(dd[a][b] + " ");
            }
            System.out.println();

        }
    }
    public static void inArraryRandom(int[][] dj,int jj) {
        Random random=new Random();
        for (int aa=0;aa<dj.length;aa++){
            for (int cc=0;cc<dj[aa].length;cc++){
                dj[aa][cc]=random.nextInt(jj);
            }
        }
    }
    /**计算2维行和的值*/
    public  static int[] geTrowSum(int cc[][]) {
        int sumh[] = new int[cc.length];
        int p = 0;
        for (int aa = 0; aa < cc.length; aa++) {
            for (int qq = 0; qq < cc[aa].length; qq++) {
                p = cc[aa][qq] + p;
            }
            sumh[aa] = p;
            p = 0;
        }

        return sumh;
    }
    /**计算2维列和的值*/
    public  static int[] getColumnSum(int cc[][]) {
        int suml[] = new int[cc[0].length];
        int pp = 0;
        for (int aa = 0; aa < cc[0].length; aa++) {
            for (int qq = 0; qq < cc.length; qq++) {
                pp += cc[qq][aa];
            }
            suml[aa] = pp;
            pp = 0;
        }
        return suml;
    }
}

